/*
 * @lc app=leetcode id=495 lang=cpp
 *
 * [495] Teemo Attacking
 */

// @lc code=start
class Solution {
public:
    int findPoisonedDuration(vector<int>& timeSeries, int duration) {

        int ans = duration;
        int last = timeSeries[0] + duration;
        int n = timeSeries.size();
       for (int i = 1; i < n; ++i) {
           int end = timeSeries[i] + duration;
           ans += end - last > duration ? duration : end - last; 
           last = end;
       }
       return ans;
    }
};
// @lc code=end

